import rlp
from Crypto.Hash import SHA256


class BlockHeader:
    def __init__(self, number):
        self.parentHash = ''
        self.stateRoot = ''
        self.transactionsRoot = ''
        self.receiptsRoot = ''
        self.dbHash = ''
        self.logBloom = ''
        self.number:int = number
        self.timestamp = 0
        self.gasLimit = 3000000000000
        self.gasUsed = 0
        self.extraData = ''
        self.sealer = 0
        self.sealerList = []
        self.hash = 0


class BlockBody:
    def __init__(self):
        self.transactions = []
        self.hash = 0
        self.sigList = []
        self.transactionsReceipts = []


class Block:
    def __init__(self, number):
        self.blockHeader = BlockHeader(number=number)
        self.blockBody = BlockBody()

    def rlp(self):
        list = [self.blockHeader.parentHash, self.blockHeader.stateRoot, self.blockHeader.transactionsRoot,
                self.blockHeader.receiptsRoot, self.blockHeader.dbHash, self.blockHeader.logBloom,
                self.blockHeader.number, self.blockHeader.timestamp, self.blockHeader.gasLimit,
                self.blockHeader.gasUsed, self.blockHeader.extraData, self.blockHeader.sealer,
                self.blockHeader.sealerList]
        self.blockHeader.hash = SHA256.new(rlp.encode(list)).hexdigest()
        self.blockBody.hash = self.blockHeader.hash
